<template>
	<view>
		<!-- 顶部样式 -->
		<view class="head">
			<view :class="{'active':tabIndex==index}" class="title" v-for="(item,index) in titleList" :key="index" @tap="change(index)" >
				<view>{{ item.title }}</view>
			</view>
		</view>
		
		<view class="items" v-for="(item,index) in list" :key="index" @tap="toDetail(item)">
			<view class="avatar">
				<view class="avatar-img">
					<image :src="item.avatar" mode=""></image>
				</view>
				<view></view>
			</view>
			<view class="info">
				<view class="info-title">{{ item.title }}</view>
				<view class="info-content">
					<view class="info-content-left">
						<i class="iconfont iconicon_dingwei icons" style="color: #0091FF;"></i>
						<text>{{ doStr(item.place) }}</text>
					</view>
					<view class="info-content-right">
						<i style="margin-left: 10rpx;color: #0091FF;" class="iconfont iconicon_riqi icons"></i>
						<text>{{ item.engagementtime }}</text>
					</view>
				</view>
				<view class="num">
					报名情况:
					<view>男<text>{{ item.addman }}</text>/{{ item.man }}</view>
					<view>女<text>{{ item.addwoman }}</text>/{{ item.woman }}</view>
				</view>
			</view>
			<view class="status" style="background-color: #FE4392;color: #FFFFFF;" v-if="item.statusStr==0">未开始</view>
			<view class="status" style="background-color: #0091FF;color: #FFFFFF;" v-if="item.statusStr==1">进行中</view>
			<view class="status" style="background-color: #D8D8D8;color: #999999;" v-if="item.statusStr==2">已结束</view>
			<view class="status" style="background-color: #D8D8D8;color: #999999;" v-if="item.activestatus==1">已结束</view>
		</view>
		
		
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex'
	export default {
		computed: {
			...mapState(['token'])
		},
		data() {
			return {
				tabIndex:0,
				page:1,
				pages:null,
				titleList:[
					{title:'我发布的'},
					{title:'我参与的'}
				],
				list:[]
			};
		},
		//分享给个人
		onShareAppMessage() {
			return {
				title: '青年交友',
				imageUrl:'https://friend.tanshishang.cn/assets/img/shareImg.png',
				path:'/pages/index/index'
			}
		},
		//上拉加载
		onReachBottom() {
			console.log('触发上拉加载');
			if (this.page < this.pages) {
				this.page++;
				if(this.tabIndex == 0){
					//我发布的
					this.getData();
				}else{
					//我参加的
					this.getData1();
				}
			} else {
				uni.showToast({
					title: '到底了!',
					icon: 'none'
				})
			}
		},
		onLoad() {
			if(this.tabIndex == 0){
				//我发布的
				this.getData();
			}else{
				//我参加的
				this.getData1();
			}
			
		},
		methods:{
			//获取数据 我发布的
			async getData() {
				try {
					let params = {
						token: this.token,
						page:this.page
					};
					let res = await this.$request.request.get('/api/engagement/myEngagement', params)
					console.log(res);
					if (res.code == 200) {
						this.list = this.list.concat(res.data.list);
						this.pages = res.data.pages;
					}
				} catch (err) {
					this.$request.error(err, this)
				}
			},
			//获取数据 我参加的
			async getData1() {
				try {
					let params = {
						token: this.token
					};
					let res = await this.$request.request.get('/api/engagement/enlistEngagement', params)
					console.log(res);
					if (res.code == 200) {
						this.list = this.list.concat(res.data.list);
						this.pages = res.data.pages;
					}
				} catch (err) {
					this.$request.error(err, this)
				}
			},
			//顶部切换
			change(e){
				this.tabIndex = e;
				
				if(this.tabIndex == 0){
					this.list = [];
					this.page = 1;
					//我发布的
					this.getData();
				}else{
					this.list = [];
					this.page = 1;
					//我参加的
					this.getData1();
				}
				
			},
			//点击进入详情
			toDetail(e){
				uni.navigateTo({
					url:'dateCirclesDetail?id='+e.id+'&type='+e.statusStr
				})
			},
			//位置切割
			doStr(e){
				if(e){
					let arr = e.split('-');
					if(arr.length>1){
						return arr[1]
					}else{
						return arr[0]
					}
				}
			}
		}
	}
</script>

<style lang="scss">
@import'dateCircles.scss'
</style>
